﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ViewPlane : MonoBehaviour {

	public Camera targetCameara;

	//这两个值决定了最后的图像用多少个像素
	public int HRes {
		get {
			if (pixelSize <= float.Epsilon) {
				Debug.LogErrorFormat ("pixelSize of ViewPlane is so small: {0}. So I cannot compute HRes value.", pixelSize);
				return 0;
			}

			return (int) (targetCameara.orthographicSize * 2 / pixelSize);
		}

	}

	public int VRes {
		get {
			if (pixelSize <= float.Epsilon) {
				Debug.LogErrorFormat ("pixelSize of ViewPlane is so small: {0}. So I cannot compute VRes value.", pixelSize);
				return 0;
			}

			return (int) (targetCameara.orthographicSize * 2 / pixelSize);
		}

	}

	//这个值决定每个在图像（png etc）中的像素的值有多少个采样点取得
	public float pixelSize;
	public float gamma;
	public float invGamma;

	public Vector2 GetPoint(float x, float y) {
		//相机位置在自身边框的中心，所以根据（x，y）和相机的size（正交）可以得到每个点的世界位置
		Vector2 topLeftCorner = new Vector2 (targetCameara.transform.position.x, targetCameara.transform.position.y) -
		                        new Vector2 (targetCameara.orthographicSize, targetCameara.orthographicSize);

		topLeftCorner += new Vector2 (pixelSize * 0.5f, pixelSize * 0.5f);

//		Debug.LogFormat ("topLeftCorner 坐标：{0} {1}", topLeftCorner.x, topLeftCorner.y);

		float h = topLeftCorner.x + pixelSize * x;
		float v = topLeftCorner.y + pixelSize * y;

		return new Vector2 (h, v);
	}

}
